<template>
    <div class="app">
        <div>
            <span>二维码地址：</span>
            <el-input clearable v-model="address" placeholder="请输入地址" style="width:200px"></el-input>
            <el-button type="success" @click="handleClick">点击生成二维码</el-button>
        </div>
        <div id="qrcode" ref="qrcode"></div>
    </div>
</template>
<script>
import QRCode from 'qrcodejs2'
export default {
    data () {
        return {
            address: '',
            qrcode: null
        }
    },
    components: { QRCode },
    methods: {
        handleClick () {
            if (!this.address) {
                this.address = 'http://www.baidu.com'
                this.qrcode = new QRCode('qrcode', {
                    width: 232, // 设置宽度
                    height: 232, // 设置高度
                    text: this.address
                })
            }
        }
    }
}
</script>
<style scoped>
.app {
    text-align: center;
    margin-top: 60px;
}

#qrcode {
    width: 232px;
    margin: 50px auto;
}
</style>
